package com.boot.message.rabbit;

import com.rabbitmq.client.Channel;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

import java.io.IOException;

/**
 * @author 霜寒 <1621856595@qq.com>
 * @description RabbitMQ消费者
 * @date 2020/5/21 16:55
 **/
@Component
public class RabbitMQListener {

    @RabbitListener(queues = "userQueue")
    public void userProcess(Message msg, Channel channel) {
        try {
            channel.basicAck(msg.getMessageProperties().getDeliveryTag(), false);
            System.out.println("user消费者收到消息  : " + msg);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    @RabbitListener(queues = "groupQueue")
    public void groupProcess(Message msg, Channel channel) {
        try {
            channel.basicAck(msg.getMessageProperties().getDeliveryTag(), false);
            System.out.println("group消费者收到消息  : " + msg);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

}
